package net.dongbob;

import javax.swing.*;

import static net.dongbob.Components.*;
import static net.dongbob.Utils.*;

public class Components
{
    public static JLabel plus1 = new JLabel("x²+");
    public static JLabel plus2 = new JLabel("x+");
    public static JLabel equal = new JLabel("=0");
    public static JTextField textTwice = new JTextField(4);
    public static JTextField textOnce = new JTextField(4);
    public static JTextField textConst = new JTextField(4);
    public static JTextArea showSolution = new ShowArea(10,10);
    public static JButton get = new GetButton("Get");
    public static JButton exit = new ExitButton("Exit");
    public static JButton clear = new ClearButton("Clear");
    public static JPanel topPanel = new TopPanel();
    public static JScrollPane bottomPanel = new BottomPanel();
    public static JSplitPane container = new Container();
}

class Container extends JSplitPane
{
    public Container()
    {
        setOrientation(JSplitPane.VERTICAL_SPLIT);
        setTopComponent(topPanel);
        setBottomComponent(bottomPanel);
        setContinuousLayout(true);
        setDividerSize(0);
    }
}

class TopPanel extends JPanel
{
    public TopPanel()
    {
        add(textTwice);
        add(plus1);
        add(textOnce);
        add(plus2);
        add(textConst);
        add(equal);
        add(get);
        add(clear);
        add(exit);
    }
}

class BottomPanel extends JScrollPane
{
    public BottomPanel()
    {
        setViewportView(showSolution);
    }
}

class ShowArea extends JTextArea
{
    public ShowArea(int rows,int columns)
    {
        super(rows,columns);
        setEditable(false);
    }
}

class GetButton extends JButton
{
    public GetButton(String text)
    {
        setText(text);
        addActionListener(e -> solve());
    }
}

class ExitButton extends JButton
{
    public ExitButton(String text)
    {
        setText(text);
        addActionListener(e -> System.exit(0));
    }
}

class ClearButton extends JButton
{
    public ClearButton(String text)
    {
        setText(text);
        addActionListener(e -> reset());
    }
}
